<?php
namespace App\Services;

use App\Models\MysqlDb\ConfigWebsiteModel;
use App\Models\StatusCode;

/**
 * Class CommonPayService
 * @package app\common\service\pay
 * @Author: TinyMeng <666@majiameng.com>
 * @Created: 2020/8/14
 */
class CommonConfigService
{
    public $company;
    public $configCode;

    /**
     * 获取配置
     * @param $company
     * @param $configCode
     * @return array
     * @author: tinymeng <666@majiameng.com>
     * @ctime:  2021/6/7 18:11
     */
    public function getParamsConfig($company,$configCode){
        $this->company = $company;
        $this->configCode = $configCode;

        $companyConfig = ConfigWebsiteModel::getPaymentConfig($company['id'],$configCode,$company['service_providers']);
        if(empty($companyConfig)){
            CommonReturn::fail(StatusCode::COMMON_NO_DATA_EXIST,"系统配置文件【{$configCode}】不能为空！");
        }

        $data = [];
        $pattern = "/^".$configCode."_(.*)/";
        foreach ($companyConfig as $key=>$value){
            if(preg_match($pattern,$key)){
                $key = substr($key,strlen($configCode.'_'));
                $data[$key] = $value;
            }
        }

        return $this->loadConfig($data);
    }

    /**
     * @param $data
     * @return mixed
     */
    public function loadConfig($data){
        return $data;
    }
}
